<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use yii\widgets\Pjax;

/* @var $this yii\web\View */
/* @var $searchModel admin\modules\rbac\models\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', '用户管理');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">
    <?php Pjax::begin(); ?>

    <p>
        <?php if (Yii::$app->user->identity->is_super): ?>
            <?php echo Html::a(Yii::t('app', '创建用户'), ['create'], ['class' => 'btn btn-success']) ?>
        <?php endif; ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'kartik\grid\SerialColumn'],
            ['class' => 'kartik\grid\ActionColumn'],
            [
                'label' => '更多操作',
                'format' => 'raw',
//                'mergeHeader' => true,
                'value' => function ($model) {
                    $url = ['allot-role', 'user_id' => $model->id];
                    return Html::a(\kartik\icons\Icon::show('universal-access'), $url, ['title' => '分配角色']);
                }
            ],
            'id',
            'username',
            'email:email',
            'idcard',
            [
                'class' => \common\components\grid\KEnumColumn::class,
                'attribute' => 'mobile_pre',
                'enum' => \common\models\file_data\MobilePre::getSelectData(),
            ],
            'mobile',
            'nickname',
            [
                'class' => '\kartik\grid\DataColumn',
                'attribute' => 'avatar_url',
                'label' => "头像",
//        'value' => function($m){
//            return $m->getAvatarImg();
//        },
//        'format' => 'raw',
            ],
            [
                'class' => \kartik\grid\DataColumn::class,
                'attribute' => 'created_at',
                'headerOptions' => [
                    'width' => '220px'
                ],
                'contentOptions' => [
                    'width' => '220px'
                ],
                'format' => ['date', 'php:Y-m-d H:i:s'],
                'filterType' => \kartik\grid\GridView::FILTER_DATE_RANGE,
                'filterWidgetOptions' => [
                    'model' => $searchModel,
                    'attribute' => 'created_at',
                    'presetDropdown' => TRUE,
                    'convertFormat' => true,
                    'pluginOptions' => [
                        'format' => 'Y-m-d',
                        'opens' => 'left',
                        'locale' => [
                            'cancelLabel' => 'Clear',
                            'format' => 'Y-m-d',
                        ],
                    ]
                ],
            ],
            [
                'class' => \kartik\grid\DataColumn::class,
                'attribute' => 'updated_at',
                'headerOptions' => [
                    'width' => '220px'
                ],
                'contentOptions' => [
                    'width' => '220px'
                ],
                'format' => ['date', 'php:Y-m-d H:i:s'],
                'filterType' => \kartik\grid\GridView::FILTER_DATE_RANGE,
                'filterWidgetOptions' => [
                    'model' => $searchModel,
                    'attribute' => 'updated_at',
                    'presetDropdown' => TRUE,
                    'convertFormat' => true,
                    'pluginOptions' => [
                        'format' => 'Y-m-d',
                        'opens' => 'left',
                        'locale' => [
                            'cancelLabel' => 'Clear',
                            'format' => 'Y-m-d',
                        ],
                    ]
                ],
            ],
            [
                'class' => \kartik\grid\DataColumn::class,
//        'class' => \common\rewrite\yiister\yii2_advanced_grid\widgets\InputColumn::class,
//        'updateAction' => ['user/column-update'],
                'attribute' => 'level',
            ],
            [
                'class' => \kartik\grid\DataColumn::class,
//        'class' => \common\rewrite\yiister\yii2_advanced_grid\widgets\InputColumn::class,
//        'updateAction' => ['user/column-update'],
                'attribute' => 'integral',
            ],
//            'token',
//            'auth_key',
//            'password_hash',
//            'tp_pwd',
            [
                'class' => \common\components\grid\KEnumColumn::class,
                'attribute' => 'status',
                'enum' => \common\models\db\User::getStatus(),
            ],
            [
                'class' => \common\components\grid\KEnumColumn::class,
                'attribute' => 'is_super',
                'label' => "超级用户",
                'enum' => \common\models\db\User::getIsSuper(),
                'visible' => Yii::$app->user->identity->is_super ? true : false,
            ],
        ],
    ]); ?>
    <?php Pjax::end(); ?>
</div>
